package com.zhang.zhangapp.bean.user;


import com.zhang.zhangapp.application.MApplication;

import org.xutils.x;

/**
 * Created by Administrator on 2018/4/2.
 */

public class UserDao {

    static UserDao userDao;

    public static UserDao getInstance() {
        if (userDao == null) {
            userDao = new UserDao();
        }
        return userDao;
    }

    public void save(User user) throws Exception {
        x.getDb(MApplication.getInstance().getDaoConfig()).delete(User.class);
        x.getDb(MApplication.getInstance().getDaoConfig()).saveOrUpdate(user);
    }

    public User queryUser() throws Exception {
        return x.getDb(MApplication.getInstance().getDaoConfig()).findFirst(User.class);
    }

    public void clearUser(int id) throws Exception {
        x.getDb(MApplication.getInstance().getDaoConfig()).deleteById(User.class, id);
    }
}
